/**
 * 账号和权限相关的权限
 */

import Axios from '@/utils/request';
import { IResources, IUserInfo } from '@/types/user-info';

// /**
//  * 认证用户并缓存
//  */
// export function verifyUserAsync(param) {
//     return Axios.asyncAjax({
//         url: '/sessionAuth/verifyUser?' + param
//     })
// }

/**
 * 认证用户并缓存
 */
export const verifyUserApi = (session: string): Promise<IUserInfo> => {
    return Axios.get('/sessionAuth/verifyUser?sessionId=' + session);
};

/**
 * 验证菜单权限是否有效
 */
export const verifyMenuAuthApi = (url: string): Promise<any> => {
    // return Axios.get('/sessionAuth/verify/verifyMenuAuth?menuUrl=' + url);
    return Axios({
        url: '/sessionAuth/verify/verifyMenuAuth?menuUrl=' + url,
        method: 'get',
        headers: { operateType: 'autoRefresh' },
    });
};

/**
 * 获取当前用户的菜单
 * @param sessionId
 */
export const queryCurrentUserMenuTree = (sessionId: string): Promise<any> => {
    // return Axios.post('/outFrame/currentUserMenuTree/sessionId', {
    //     sessionId: sessionId,
    // });
    return Axios({
        url: '/outFrame/currentUserMenuTree/sessionId',
        data: { sessionId: sessionId },
        method: 'post',
        headers: { operateType: 'autoRefresh' },
    });
};

/**
 * 获取当前用户的快捷访问菜单
 * @param sessionId
 */
export const queryCurrUserMenuCollect = (sessionId: string): Promise<any> => {
    return Axios({
        url: 'outFrame/queryCurrUserMenuCollect/sessionId',
        data: { sessionId: sessionId },
        method: 'post',
        headers: { operateType: 'autoRefresh' },
    });
};

/**
 * 登录账号
 * @param data
 */
export const login = (data: { userName: string; password: string }): Promise<IUserInfo> => {
    return Axios.post('/outFrame/login', data);
};

/**
 * 退出登录
 */
export const logout = (): Promise<boolean> => {
    return Axios.get('/outFrame/logout');
};

/**
 * 修改密码
 * @param oldPassword
 * @param newPassword
 */
export const changePassword = (oldPassword: string, newPassword: string): Promise<void> => {
    return Axios.post('/outFrame/update/password', {
        oldPassword: oldPassword,
        newPassword: newPassword,
    });
};
